const app = getApp()
const util = require('../../utils/util.js')

Page({
  data: {
    itemNum: 0,
    currentTab: 0,
    loading: 1,
    show: 1,
    stop: 0,
    changeSearch: 0, //改变搜索框状态
    changeSelect: 0,
    scrollTop: null,
    noMore: false, //判断是否大于5条
    filter: {
      lastAddress: [], //上次选中的地址
      lastClass: [], //上次选中的班组
      lastStatus: [], //上次选中状态
      filterList: {
        'address': [],
        'className': [],
        'status': []
      }, //筛选条件数组
      selectListTemp: {
        'notice': '请选择条件',
        'list': []
      }, //临时存放搜索结果
    },
    searchInput: null,
    showTxt: '收起',
    invalidTitle: "提示",
    invalidArea: "请确保您已到达巡检地点！",
    locationContent: "请在系统设置-应用权限管理中开启允许微信使用地理位置的开关",
    itemList: [],

  },


  //事件处理函数
  onLoad: function (options) {

 

    let that = this
    //从首页跳转
    if (options) {
      let categoryId = parseInt(options.currentcategoryId)||wx.getStorageSync('navData')[0].categoryId
      let allList = wx.getStorageSync('allList')
      let itemList = that.showCurrentCategory(categoryId)||[]
      that.setData({
        fromIndex: 1,
        loading: 0,
        idxcount: options.idxcount,
        currentcategoryId: parseInt(options.currentcategoryId),
        categoryIdList: options.categoryIdList,
        itemList: itemList,
        allList: allList,
        categoryName: options.categoryName
      })

//提交巡检内容跳转



    }
    wx.getSystemInfo({
      success: (res) => {
        //x以上系列适配，没做
        let modelmes = res.model;
        if (modelmes.search('iPhone X') != -1) {
          this.setData({
            isIphoneX: true
          })
        }
        this.setData({
          pixelRatio: res.pixelRatio,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      },
    })

    let navData = []
    wx.getStorage({
      key: 'navData',
      success: function (res) {
        that.setData({
          navData: res.data
        })
      },
    })

    let singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: options.id,
      //动态根据配置的大项数目给间距
      navScrollLeft: (options.id - 2) * singleNavWidth
    })

    wx.request({
      url: app.inspectUrl + '/WeChat/weChatSystem/getSchoolUUIDS',
      method: 'POST',
      data: app.globalData.departmentId,
      dataType: 'json',
      success: res => {
        this.setData({
          uuids: res.data.split(",")
        })
      }
    })


  },

  showCurrentCategory: function (categoryId) {
    wx.request({
      url: app.inspectUrl + '/WeChat/weChatSystem/getInspectInfo2',
      method: 'POST',
      data: {
        schoolId: app.globalData.departmentId,
        userId: app.globalData.userId,
        identityId: app.globalData.identityId,
        categoryId: parseInt(categoryId)
      },
      dataType: 'json',
      success: res => {
        if(res.data.length != 0){
          var itemList = []
          itemList = (res.data)[0].itemList
          for(let i=0;i<itemList.length;i++){
            itemList[i].category = this.data.categoryName;
          }
          wx.setStorageSync('listSelect', itemList)
          this.setData({
            itemList: itemList,
            loading: 0
          })
        }else {
          this.setData({
            itemList: [],
            loading: 0
          })
        }
      }

    })

  }, //筛选条件初始化（去重）
  duplication: function (listSelect) {
    let that = this,
      // listSelectNew = [],
      listSelectObjNew = {},
      listTempObj = {}
    listSelectObjNew['startTime'] = []
    listSelectObjNew['endTime'] = []
    listSelectObjNew['className'] = []
    listSelectObjNew['address'] = []
    listSelectObjNew['status'] = [
      // {
      //   'value': '已完成',
      //   'checked': false
      // },
      {
        'value': '未完成',
        'checked': false
      }, {
        'value': '未通过',
        'checked': false
      }, {
        'value': '已处理',
        'checked': false
      }
    ]
    listTempObj = {
      'notice': '请选择条件',
      'list': []
    }
    //临时存放搜索结果
    // listSelectNew.push(listSelectObjNew)

    console.log("that.data.currentTab ", that.data.currentTab, listSelect);

    // for (let i = 0; i < listSelect[that.data.currentTab].startTime.length; i++) {
    //   let flag = true
    //   for (let j = 0; j < listSelectObjNew.startTime.length; j++) {
    //     if (listSelect[that.data.currentTab].startTime[i].value == listSelectObjNew.startTime[j].value) {
    //       flag = false
    //     }
    //   }
    //   if (flag) {
    //     listSelectObjNew.startTime.push(listSelect[that.data.currentTab].startTime[i])
    //   }
    // }

    // for (let i = 0; i < listSelect[that.data.currentTab].endTime.length; i++) {
    //   let flag = true
    //   for (let j = 0; j < listSelectObjNew.endTime.length; j++) {
    //     if (listSelect[that.data.currentTab].endTime[i].value == listSelectObjNew.endTime[j].value) {
    //       flag = false
    //     }
    //   }
    //   if (flag) {
    //     listSelectObjNew.endTime.push(listSelect[that.data.currentTab].endTime[i])
    //   }
    // }

    for (let i = 0; i < listSelect[that.data.currentTab].className.length; i++) {
      let flag = true
      for (let j = 0; j < listSelectObjNew.className.length; j++) {
        if (listSelect[that.data.currentTab].className[i].value == listSelectObjNew.className[j].value) {
          flag = false
        }
      }
      if (flag) {
        listSelectObjNew.className.push(listSelect[that.data.currentTab].className[i])
      }
    }
    for (let i = 0; i < listSelect[that.data.currentTab].address.length; i++) {
      let flag = true
      for (let j = 0; j < listSelectObjNew.address.length; j++) {
        if (listSelect[that.data.currentTab].address[i].value == listSelectObjNew.address[j].value) {
          flag = false
        }
      }
      if (flag) {
        listSelectObjNew.address.push(listSelect[that.data.currentTab].address[i])
      }
    }
    let curListSelect = 'filter.curListSelect',
      temp = 'filter.selectListTemp'

    console.log("listSelectObjNew", listSelectObjNew);

    this.setData({
      [curListSelect]: listSelectObjNew,
      // [temp]: listTempObj
    })

  },
  onShow: function () {
    let listSelected = wx.getStorageSync('listSelect')


    this.getlist()

    this.setData({
      itemList: listSelected
    })

  },


  onHide: function () {
    this.setData({
      stop: 1
    })
    wx.stopBeaconDiscovery()
  },


  onUnload: function () {
    this.setData({
      stop: 1
    })
    wx.stopBeaconDiscovery()
  },

  toInspList: function (e) {
    console.log("e.currentTarget.dataset.item" + e.currentTarget.dataset.item)
    let item = e.currentTarget.dataset.item
    item.inspectPlanId = []
    for (let i = 0; i < item.idAndName.length; i++) {
      item.inspectPlanId.push(item.idAndName[i].inspectPlanId)
    }

    // console.log(e.currentTarget.dataset.item);

    wx.setStorageSync("inspItemList", e.currentTarget.dataset.item)
    wx.navigateTo({
      url: `/pages/inspectItemList/inspectItemList?inspectPlanId=${item.inspectPlanId}&address=${item.address}&categoryName=${this.data.categoryName}`,
    })
  },

  //加载5条数据
  getTenListForOneItem: function (list) {
    //加载每页最多显示5条
    // let listShow = []
    const res = wx.getStorageInfoSync()
    let listShow = [],
      backFromList = []
    for (let i = 0; i < list.length; i++) {
      let itemtmp = [],
        itemListShow = {}
      let itemListLength = list[i].itemList.length > 5 ? 5 : list[i].itemList.length

      if (res.keys.includes('inspItemList')) {
        itemListLength = list[i].itemList.length
        backFromList[i] = true
      } else {
        backFromList[i] = false
      }

      for (let j = 0; j < itemListLength; j++) {
        itemtmp[j] = list[i].itemList[j]
      }
      itemListShow = {
        itemList: itemtmp,
        searchInput: null,
        cantLoad: list[i].itemList.length > 5 ? false : true
      }
      listShow[i] = itemListShow
    }
    this.setData({
      list: listShow
    })
    this.setData({
      // noMore: this.data.list[this.data.currentTab].cantLoad
      // noMore: backFromList[this.data.currentTab] ? true : this.data.list[this.data.currentTab].cantLoad
    })
  },

  //获取数据处理
  getlist: function () {

   

    // wx.showLoading({
    //   title: '加载中',
    //   mask: true
    // })

    let list = [],
      data = [],
      listSelect = [],
      result = [],
      done = [],
      undone = [],
      firObj = {},
      startTimeList = [],
      endTimeList = [],
      classNameList = [],
      addressList = [];


    //item开头数组用于筛选 放缓存
    data = wx.getStorageSync('allList') || this.data.allList;

    // 遍历所有数据，处理待显示项
    for (let i = 0; i < data.length; i++) {
    
      let resDataItemListLength = data[i].itemList.length;
      for (let j = 0; j < resDataItemListLength; j++) {

        let startTimeObjTem = {},
          endTimeObjTem = {},
          classNameObjTem = {},
          addressObjTem = {};
        if (data[i].itemList[j].undone == 0) {
          // if (data[i].itemList[j].showIndex == 1)
            done.push(data[i].itemList[j])
        } else {
          undone.push(data[i].itemList[j])

        

        }
        startTimeObjTem['value'] = data[i].itemList[j].deadline
        endTimeObjTem['value'] = data[i].itemList[j].finishTime
        classNameObjTem['value'] = data[i].itemList[j].name
        addressObjTem['value'] = data[i].itemList[j].address
        startTimeObjTem['checked'] = false
        endTimeObjTem['checked'] = false
        classNameObjTem['checked'] = false
        addressObjTem['checked'] = false
        startTimeList.push(startTimeObjTem)
        endTimeList.push(endTimeObjTem)
        classNameList.push(classNameObjTem)
        addressList.push(addressObjTem)
// console.log("classNameObjTem", classNameObjTem);

        //二层结束
        // done.sort(function (a, b) {
        //   return b.finLong - a.finLong
        // })
        result = undone.concat(done)||[]

        firObj['startTime'] = startTimeList
        firObj['endTime'] = endTimeList
        firObj['className'] = classNameList
        firObj['address'] = addressList
        listSelect.push(firObj)
        list[i] = {
          itemList: result,
          searchInput: null
        }
      }
    }
    //处理后的所有数据listOriginal


    wx.setStorageSync('inspectitemOriginal', list)
    // wx.setStorageSync('listSelect', listSelect)
    //安监主任默认显示未完成和有异常
    // if (app.globalData.identityId == 4) {
    if (app.globalData.features.indexOf("34") != -1) {
      console.log('list', list)
      for (let i = 0; i < list.length; i++) {
        for (let j = list[i].itemList.length - 1; j >= 0; j--) {
          if (list[i].itemList[j].showIndex == 0) list[i].itemList.splice(j, 1)
        }
      }
    }
    this.getTenListForOneItem(list)
    this.setData({
      // loading: 0
    })

//二轮循环后的数组为每个itemlist，需要去重
    this.duplication(listSelect)



  },

  //滑到底部加载
  scrolltolower: function () {
    this.showCurrentCategory(this.data.currentcategoryId)

  },

  addList: function (originalList) {
    let that = this,
      nowList = that.data.list[that.data.currentTab].itemList
    if (nowList.length == originalList.length) {
      that.setData({
        noMore: true
      })
    } else {
      let addLength = originalList.length - nowList.length > 5 ? 5 : originalList.length - nowList.length,
        listStr = `list[${that.data.currentTab}].itemList`
    
      nowList = nowList.concat(originalList.slice(nowList.length, nowList.length + addLength))
      // console.log(nowList)

      that.setData({
        [listStr]: nowList
      })
      // console.log(this.data.list)
    }
  },

  //从搜索按钮 点击搜索
  searchButton: function (e) {
    let input = app.trim(e.detail.value.input)
    this.searchItem(input)
  },

  //从键盘确定 点击搜索
  searchKeyboard: function (e) {
    let input = app.trim(e.detail.value)
    this.searchItem(input)
  },

  // 从listOriginal查，然后修改缓存，设置list
  // 只能搜索当前类别下的项目 全部搜索要放在单独页面做
  searchItem: function (input) {
    if (!input) {
      wx.showToast({
        title: '请输入关键字！',
        icon: 'none',
        duration: 800,
        mask: true
      })
      return
    }
    this.data[`tmpList${this.data.currentTab}`] = null
    //判断 是否有“当前关键字：”
    input.indexOf("当前关键字：") == 0 ?
      (input = input.replace("当前关键字：", '')) : '';
    let index = this.data.currentTab,
      listOriginal = wx.getStorageSync('listSelect');

    //filter 返回满足过滤条件项组成的数组
    let list = listOriginal.filter(p => {
      return p.address.includes(input) || p.checkItem.includes(input) || p.deadline.includes(input) || p.name.includes(input) || p.finishTime.includes(input) || p.timeLeft.includes(input)
    })
    if (list.length == 0) {
      wx.showToast({
        title: '未搜索到符合条件的项目，请重新输入！',
        icon: 'none',
        duration: 800,
        mask: true
      })
      return
    }
    let listStr = `list[${index}].itemList`,
      tmpList = `tmpList${index}.itemList`,
      inputStr = `list[${index}].searchInput`,
      cantLoadStr = `list[${index}].cantLoad`
    if (list.length < 6) {
      this.setData({
        [listStr]: list,
        [inputStr]: "当前关键字：" + input,
        [cantLoadStr]: true
      })
    } else {
      this.setData({
        [tmpList]: list
      })
      //splice数组发生改变
      let tmp = list.splice(0, 5)
      this.setData({
        [listStr]: tmp,
        [inputStr]: "当前关键字：" + input,
        [cantLoadStr]: false
      })
    }

    this.setData({
      searchInput: this.data.list[index].searchInput,
      noMore: this.data.list[index].cantLoad,
      scrollTop: 1
    })
    wx.showToast({
      title: '搜索成功！',
      icon: 'none',
      duration: 800
    })
 
    // 列表显示搜索后的结果
    this.setData({
      itemList: list
    })
  },

  //搜索框

  //获取焦点 删除“当前关键字：”
  getInputStr: function (e) {
    if (e.detail.value.indexOf("当前关键字：") == -1) {
      e.detail.value = e.detail.value.replace("当前关键字：", '')
      this.setData({
        searchInput: ''
      })
    }
  },

  changeSearch: util.throttle(function () {
    this.setData({
      changeSelect: this.data.changeSelect == 0 ? 0 : this.data.changeSelect == 1 ? 2 : 2,
      changeSearch: this.data.changeSearch == 0 ? 1 : this.data.changeSearch == 1 ? 2 : 1
    })
  }, 500),

  hideDropDown: function () {
    this.setData({
      changeSearch: this.data.changeSearch == 0 ? 0 : this.data.changeSearch == 1 ? 2 : 2,
      changeSelect: this.data.changeSelect == 0 ? 0 : this.data.changeSelect == 1 ? 2 : 2
    })
  },

  //刷新
  refreshData: util.throttle(function () {

    this.data[`tmpList${this.data.currentTab}`] = null
    this.setData({
      fromIndex: 0
    })
    this.showCurrentCategory(this.data.currentcategoryId)
    wx.showToast({
      title: '刷新成功！',
      icon: 'none',
      duration: 800
    })
    // this.getlist()
    this.setData({
      searchInput: null,
      scrollTop: 1
    })
  }, 1000),


  //筛选
  showSelect: function () {

    this.getlist()

    console.log(this.data.filter.curListSelect)
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(800).step()
    this.setData({
      animationSelect: animation.export(),
      showSelectStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationSelect: animation.export()
      })
    }.bind(this), 300)
  },
  // 隐藏遮罩层
  hideSelect: function (e) {
    // console.log(e)

    let listSelect = wx.getStorageSync('listSelect')
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(800).step()
    this.setData({
      animationSelect: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationSelect: animation.export(),
        showSelectStatus: false
      })
    }.bind(this), 300)

    
    let filter = this.data.filter
    filter.filterList = {
      'address': [],
      'className': [],
      'status': []
    }
    filter.lastAddress = []
    filter.lastClass = []
    filter.lastStatus = []
    this.setData({
      filter: filter
    })
    if (e != 'close' && e.target.dataset.type == 'showAll') {
      this.data[`tmpList${this.data.currentTab}`] = null

      this.setData({
        scrollTop: 1
      })
    }
    console.log(this.data.filter)
  },


  //筛选条件-地点
  addressChange: function (e) {

  
    
    let lastList = this.data.filter.lastAddress,
      dataList = this.data.filter.curListSelect.address,
      filterList = this.data.filter.filterList.address,
      str1 = 'filter.lastAddress',
      str2 = 'address',
      strfilter = 'filter.filterList.address'
    this.dealFilter(e, lastList, dataList, filterList, str1, str2, strfilter)
  },

  //筛选条件-班组
  classChange: function (e) {
    let lastList = this.data.filter.lastClass,
      dataList = this.data.filter.curListSelect.className,
      filterList = this.data.filter.filterList.className,
      str1 = 'filter.lastClass',
      str2 = 'className',
      strfilter = 'filter.filterList.className'
    this.dealFilter(e, lastList, dataList, filterList, str1, str2, strfilter)
  },

  //筛选条件-状态
  statusChange: function (e) {

 
    
    let lastList = this.data.filter.lastStatus,
      dataList = this.data.filter.curListSelect.status,
      filterList = this.data.filter.filterList.status,
      str1 = 'filter.lastStatus',
      str2 = 'status',
      strfilter = 'filter.filterList.status'
    this.dealFilter(e, lastList, dataList, filterList, str1, str2, strfilter)
  },
  //筛选处理
  dealFilter: function (e, lastList, dataList, filterList, str1, str2, strfilter) {
    let arr = []
    for (let i = 0; i < e.detail.value.length; i++) {
      let index = e.detail.value[i].split('-')[0]
      arr.push(index)
    }
    this.setData({
      [str1]: arr
    })
    //cur 这次改变的checkbox索引号
    let cur = lastList.concat(arr).filter(function (v, i, array) {
      return array.indexOf(v) === array.lastIndexOf(v);
    })
    // console.log(cur)
    let dataStr = 'filter.curListSelect.' + str2 + '[' + cur + '].checked',
      value = dataList[cur].value
    //判断filterList有无当前值 删除或增加
    filterList.indexOf(value) == -1 ? filterList.push(value) : filterList.splice(filterList.indexOf(value), 1)
    this.setData({
      [dataStr]: dataList[cur].checked == false ? true : false,
      [strfilter]: filterList
    })

    let curIndex = this.data.currentTab,
      list = wx.getStorageSync('listSelect')
    //筛选上下关系为与 左右关系为或
    if (this.data.filter.filterList.address.length > 0) {
      let tempList = []
      for (let i = 0; i < this.data.filter.filterList.address.length; i++) {
        tempList = tempList.concat(list.filter(p => {
          return p.address.includes(this.data.filter.filterList.address[i])
        }))
      }
      list = tempList
    }
    if (this.data.filter.filterList.className.length > 0) {
      let tempList = []
      for (let i = 0; i < this.data.filter.filterList.className.length; i++) {
        tempList = tempList.concat(list.filter(p => {
          return p.name.includes(this.data.filter.filterList.className[i])
        }))
      }
      list = tempList
    }
    if (this.data.filter.filterList.status.length > 0) {
      let tempList = []
      for (let i = 0; i < this.data.filter.filterList.status.length; i++) {
        // if (this.data.filter.filterList.status[i] == '已完成') {
        //   tempList = tempList.concat(list.filter(p => p.timeLeft.includes('已完成')))
        // } else 
        if (this.data.filter.filterList.status[i] == '未完成') {
          tempList = tempList.concat(list.filter(p => p.finishTime.includes('未完成')))
        } else if (this.data.filter.filterList.status[i] == '未通过') {
          tempList = tempList.concat(list.filter(p => p.isUnusual == 1))
        } else if (this.data.filter.filterList.status[i] == '已处理') {
          tempList = tempList.concat(list.filter(p => p.isDeal == 1))
        }
      }
      list = Array.from(new Set(tempList))
    }
    console.log('最终')
    console.log(list)
    let notice = '',
      noticeStr = 'filter.selectListTemp.notice',
      listStr = 'filter.selectListTemp.list',
      selectListTemp = {
        itemList: list,
        searchInput: null
      }
    if (!(this.data.filter.filterList.address.length == 0 && this.data.filter.filterList.className.length == 0 && this.data.filter.filterList.status.length == 0)) {
      notice = '本页面下共' + list.length + '个结果符合当前条件'
      // selectListTemp.itemList = wx.getStorageSync('listSelect ')
      //若搜索筛选按当前数据 则修改为当前searchInput值
      // selectListTemp['searchInput']=null
      this.setData({
        [noticeStr]: notice,
        [listStr]: selectListTemp
      })
    } else {
      notice = '请选择条件'
      this.setData({
        [noticeStr]: notice,
        [listStr]: selectListTemp
      })
    }
  },

  //确定筛选
  confirmSelect: function () {

    
    if (this.data.filter.selectListTemp.notice == '请选择条件') {
      wx.showToast({
        title: '请选择条件！',
        icon: 'none',
        duration: 800
      })
      return
    } else if (this.data.filter.selectListTemp.notice == '共0个结果符合当前条件') {
      wx.showToast({
        title: '筛选失败，没有找到符合条件的结果，请重试！',
        icon: 'none',
        duration: 800
      })
      return
    }
    this.data[`tmpList${this.data.currentTab}`] = null
    let curIndex = this.data.currentTab,
      list = 'list[' + curIndex + ']',
      tmpList = `tmpList${curIndex}`
    if (this.data.filter.selectListTemp.list.itemList.length < 6) {
      this.data.filter.selectListTemp.list["cantLoad"] = true
      this.setData({
        [list]: this.data.filter.selectListTemp.list,
        itemList:this.data.filter.selectListTemp.list.itemList
      })
    } else {
      this.data.filter.selectListTemp.list["cantLoad"] = false
      // console.log(this.data.filter.selectListTemp.list)
      this.setData({
        [tmpList]: this.data.filter.selectListTemp.list,
        itemList:this.data.filter.selectListTemp.list.itemList
      })
      this.data.filter.selectListTemp.list.itemList = this.data.filter.selectListTemp.list.itemList.splice(0, 5)
      this.setData({
        [list]: this.data.filter.selectListTemp.list,
        itemList:this.data.filter.selectListTemp.list.itemList
      })
    }
    this.setData({
      searchInput: null,
      noMore: this.data.filter.selectListTemp.list.cantLoad,
      scrollTop: 1,
      selected: 1
    })
    wx.showToast({
      title: '筛选成功！',
      icon: 'none',
      duration: 800
    })
    // console.log(this.data.list)
    //hideSelect在自己关闭或查看全部时需要传参，这里传个没有意义的e
    let e = 'close'
    this.hideSelect(e)
  },

  resetData: function () {
    const listSelect = wx.getStorageSync('listSelect')
    let filter = this.data.filter
    // this.duplication(listSelect)
    filter.filterList = {
      'address': [],
      'className': [],
      'status': []
    }
    filter.lastAddress = []
    filter.lastClass = []
    filter.lastStatus = []
    this.setData({
      filter: filter
    })
  },


  switchNav: util.throttle(function (event) {
    if(event.currentTarget.dataset.current == this.data.currentTab) {
      return;
    }
    const listSelect = wx.getStorageSync('listSelect')
    this.setData({
      loading: 1,
      itemList:listSelect  
    })


    let cur = event.currentTarget.dataset.current;

    let currentcategoryId = event.currentTarget.dataset.currentcategoryid

    let categoryName = event.currentTarget.dataset.categoryname

    let singleNavWidth = this.data.windowWidth / 5;

    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur,
        currentcategoryId: currentcategoryId,
        categoryName: categoryName
      })
      let curData = this.data.currentTab
      this.setData({
        currentcategoryId: currentcategoryId,
        // noMore: this.data.list[curData].cantLoad,
        noMore: true,
        navScrollLeft: (curData - 2) * singleNavWidth
        // searchInput: this.data.list[curData].searchInput,
      })

      this.showCurrentCategory(currentcategoryId)

      console.log("wodianli");
 
      this.duplication(listSelect)
    }
  }, 100),

  switchTab: util.throttle(function (event) {
    console.log(event)
    let cur = event.detail.current;
    let singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: cur
    })
    let curData = this.data.currentTab
    this.setData({
      // noMore: this.data.list[curData].cantLoad,
      noMore: true,
      searchInput: this.data.list[curData].searchInput,
      navScrollLeft: (curData - 2) * singleNavWidth
    });
    let listSelect = wx.getStorageSync('listSelect')
    this.duplication(listSelect)
  }, 200),


  showModalOwn: function () {
    let that = this
    wx.hideLoading()
    wx.stopBeaconDiscovery()
    wx.showModal({
      title: that.data.invalidTitle,
      content: that.data.invalidArea,
      showCancel: false
    })
  },

  switchChange: function (e) {
    let itemIndex = parseInt(e.currentTarget.id.split('-')[0])
    let detailIndex = parseInt(e.currentTarget.id.split('-')[1])
    let item = this.data.list[itemIndex].itemList[detailIndex]
    let showList = "list[" + itemIndex + "].itemList[" + detailIndex + "].showList"
    if (item.showList == null) {
      item.showList = 1
    }
    let num = item.showList == 1 ? 0 : 1
    this.setData({
      [showList]: num
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
this.refreshData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.refreshData()

  },

  //暂时没用
  // showEvent: function (e) {
  //   let itemIndex = parseInt(e.currentTarget.id.split('-')[0]),
  //     detailIndex = parseInt(e.currentTarget.id.split('-')[1]),
  //     showChecked = "list[" + itemIndex + "].itemList[" + detailIndex + "].showChecked",
  //     select = "list[" + itemIndex + "].itemList[" + detailIndex + "].select",
  //     item = this.data.list[itemIndex].itemList[detailIndex],
  //     uncheckedNum = 0,
  //     checkedNum = 0,
  //     selectCheck = null
  //   for (let i = 0; i < item.idAndName.length; i++) {
  //     if (item.idAndName[i].checked == 0) {
  //       uncheckedNum++;
  //     } else {
  //       checkedNum++;
  //     }
  //   }
  //   if (e.currentTarget.dataset.checked == 0) {
  //     selectCheck = checkedNum
  //   } else if (e.currentTarget.dataset.checked == 1) {
  //     selectCheck = uncheckedNum
  //   }
  //   this.setData({
  //     [select]: selectCheck,
  //     [showChecked]: e.currentTarget.dataset.checked
  //   })
  // },



})